import csv
#把字典到csv中
users = [
    {"name":"张安","age":22,"username":"za","password":"123"},
    {"name":"李四","age":22,"username":"za","password":"123"},
    {"name":"王五","age":23,"username":"za","password":"123"},
    {"name":"赵六","age":24,"username":"za","password":"123"},
    {"name":"筑起","age":25,"username":"za","password":"123"},
    {"name":"站六","age":21,"username":"za","password":"123"},
    {"name":"草擦","age":22,"username":"za","password":"123"},
    {"name":"刘备","age":23,"username":"za","password":"123"},
]
with open("user.csv","w",encoding="utf-8",newline="") as f:
    # 1.创建顶部标题
    fn = ["name","age","username","password"]
    # 2.创建writer
    writer = csv.DictWriter(f,fieldnames=fn)
    # 3.写标题
    writer.writeheader()
    # 4.写内容
    writer.writerows(users)